import org.apache.log4j.Logger;

/**
 * A module represents a basic part of the application.
 * 
 * @author marco.zanger
 */
public abstract class Module {

  /** The logger, daddy, what else? */
  private final Logger log = Logger.getLogger(this.getClass());

  public Module() {
    log.info(this.getClass().toString() + " started.");
  }

  public void update() {
    if (this.needsToBeUpdated()) {
      this.updateMe();
      log.info(this.getClass().toString() + " was updated.");
    }
  }

  /** This method shouldn't be called from anywhere. Use the update */
  protected abstract void updateMe();

  public abstract boolean needsToBeUpdated();

  public void info(String infoMessage) {
    log.info(infoMessage);
  }

  public void warning(String warningMessage) {
    log.warn(warningMessage);
  }

  public void error(String errorMessage) {
    log.error(errorMessage);
  }
}
